import { createRouter, createWebHistory } from 'vue-router'//createWebHashHistory地址带井号
import {useUserStore} from '@/stores'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {path:'/login',component:()=>import('@/views/login/LoginPage.vue')},
    {
      path:'/',
      component:()=>import('@/views/layout/LayoutContainer.vue'),
      redirect:'/schedule/plan',
      children:[
        {
          path:'/schedule/cheer',
          component:()=>import('@/views/schedule/ClassCheer.vue')
        },
        {
          path:'/schedule/plan',
          component:()=>import('@/views/schedule/PlanShow.vue')
        },
        {
          path:'/schedule/class',
          component:()=>import('@/views/schedule/ClassShow.vue')
        },
        {
          path:'/schedule/echart',
          component:()=>import('@/views/schedule/ClassEcharts.vue')
        },
        {
          path:'/user/profile',
          component:()=>import('@/views/user/UserProfile.vue')
        },
        {
          path:'/user/avatar',
          component:()=>import('@/views/user/UserAvatar.vue')
        },
        {
          path:'/user/password',
          component:()=>import('@/views/user/UserPassword.vue')
        },
      ]
    }
  ]
})

router.beforeEach((to)=>{
  const useStore = useUserStore()
  if(!useStore.token && to.path !== '/login') return '/login'

  return true
})

export default router
